#include "gtkcssstylepropertyprivate.h"
#include "gtkstylepropertiesprivate.h"
+typedef struct {
+ GtkCssSection *section;
+ const GValue *value;
+} GtkCssLookupValue;
+
struct _GtkCssLookup {
- GtkBitmask *missing;
- const GValue *values[1];
+ GtkBitmask *missing;
+ GtkCssLookupValue values[1];
};
GtkCssLookup *
GtkCssLookup *lookup;
guint n = _gtk_css_style_property_get_n_properties ();
- lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (const GValue *) * n);
+ lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (GtkCssLookupValue) * n);
lookup->missing = _gtk_bitmask_new ();
_gtk_bitmask_invert_range (lookup->missing, 0, n);
{
g_return_val_if_fail (lookup != NULL, FALSE);
- return lookup->values[id] == NULL;
+ return lookup->values[id].value == NULL;
}
/**
* _gtk_css_lookup_set:
* @lookup: the lookup
* @id: id of the property to set, see _gtk_style_property_get_id()
+ * @section: (allow-none): The @section the value was defined in or %NULL
* @value: the "cascading value" to use
*
* Sets the @value for a given @id. No value may have been set for @id
* before. See _gtk_css_lookup_is_missing(). This function is used to
- * set the "winning declaration" of a lookup.
+ * set the "winning declaration" of a lookup. Note that for performance
+ * reasons @value and @section are not copied. It is your responsibility
+ * to ensure they are kept alive until _gtk_css_lookup_free() is called.
**/
void
-_gtk_css_lookup_set (GtkCssLookup *lookup,
- guint id,
- const GValue *value)
+_gtk_css_lookup_set (GtkCssLookup *lookup,
+ guint id,
+ GtkCssSection *section,
+ const GValue *value)
{
g_return_if_fail (lookup != NULL);
g_return_if_fail (_gtk_bitmask_get (lookup->missing, id));
g_return_if_fail (value != NULL);
_gtk_bitmask_set (lookup->missing, id, FALSE);
- lookup->values[id] = value;
+ lookup->values[id].value = value;
+ lookup->values[id].section = section;
}
/**
* by following this pseudo-algorithm:
* 1) Identify all declarations that apply to the element
*/
- if (lookup->values[i] != NULL)
+ if (lookup->values[i].value != NULL)
{
/* 2) If the cascading process (described below) yields a winning
* declaration and the value of the winning declaration is not
* ‘initial’ or ‘inherit’, the value of the winning declaration
* becomes the specified value.
*/
- if (!G_VALUE_HOLDS (lookup->values[i], GTK_TYPE_CSS_SPECIAL_VALUE))
+ if (!G_VALUE_HOLDS (lookup->values[i].value, GTK_TYPE_CSS_SPECIAL_VALUE))
{
- result = lookup->values[i];
+ result = lookup->values[i].value;
}
else
{
- switch (g_value_get_enum (lookup->values[i]))
+ switch (g_value_get_enum (lookup->values[i].value))
{
case GTK_CSS_INHERIT:
/* 3) if the value of the winning declaration is ‘inherit’,
break;
default:
/* This is part of (2) above */
- result = lookup->values[i];
+ result = lookup->values[i].value;
break;
}
}
#include <glib-object.h>
#include "gtk/gtkbitmaskprivate.h"
+#include "gtk/gtkcsssection.h"
#include "gtk/gtkstylecontext.h"
#include "gtk/gtkstyleproperties.h"
guint id);
void _gtk_css_lookup_set (GtkCssLookup *lookup,
guint id,
+ GtkCssSection *section,
const GValue *value);
GtkStyleProperties * _gtk_css_lookup_resolve (GtkCssLookup *lookup,
GtkStyleContext *context);
if (!_gtk_css_lookup_is_missing (lookup, id))
continue;
- _gtk_css_lookup_set (lookup, id, &value->value);
+ _gtk_css_lookup_set (lookup, id, value->section, &value->value);
}
}
}
}
static void
-_gtk_css_shorthand_property_register (GParamSpec *pspec,
+_gtk_css_shorthand_property_register (const char *name,
+ GType value_type,
const char **subproperties,
GtkStyleUnpackFunc unpack_func,
GtkStylePackFunc pack_func,
g_return_if_fail (unpack_func != NULL);
node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
- "name", pspec->name,
- "value-type", pspec->value_type,
+ "name", name,
+ "value-type", value_type,
"subproperties", subproperties,
NULL);
- node->pspec = pspec;
node->pack_func = pack_func;
node->unpack_func = unpack_func;
node->parse_func = parse_func;
const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
- _gtk_css_shorthand_property_register (g_param_spec_boxed ("font",
- "Font Description",
- "Font Description",
- PANGO_TYPE_FONT_DESCRIPTION, 0),
+ _gtk_css_shorthand_property_register ("font",
+ PANGO_TYPE_FONT_DESCRIPTION,
font_subproperties,
unpack_font_description,
pack_font_description,
NULL);
- _gtk_css_shorthand_property_register (g_param_spec_boxed ("margin",
- "Margin",
- "Margin",
- GTK_TYPE_BORDER, 0),
+ _gtk_css_shorthand_property_register ("margin",
+ GTK_TYPE_BORDER,
margin_subproperties,
unpack_margin,
pack_margin,
NULL);
- _gtk_css_shorthand_property_register (g_param_spec_boxed ("padding",
- "Padding",
- "Padding",
- GTK_TYPE_BORDER, 0),
+ _gtk_css_shorthand_property_register ("padding",
+ GTK_TYPE_BORDER,
padding_subproperties,
unpack_padding,
pack_padding,
NULL);
- _gtk_css_shorthand_property_register (g_param_spec_boxed ("border-width",
- "Border width",
- "Border width, in pixels",
- GTK_TYPE_BORDER, 0),
+ _gtk_css_shorthand_property_register ("border-width",
+ GTK_TYPE_BORDER,
border_width_subproperties,
unpack_border_width,
pack_border_width,
NULL);
- _gtk_css_shorthand_property_register (g_param_spec_int ("border-radius",
- "Border radius",
- "Border radius, in pixels",
- 0, G_MAXINT, 0, 0),
+ _gtk_css_shorthand_property_register ("border-radius",
+ G_TYPE_INT,
border_radius_subproperties,
unpack_border_radius,
pack_border_radius,
border_radius_value_parse);
- _gtk_css_shorthand_property_register (g_param_spec_boxed ("border-color",
- "Border color",
- "Border color",
- GDK_TYPE_RGBA, 0),
+ _gtk_css_shorthand_property_register ("border-color",
+ GDK_TYPE_RGBA,
border_color_subproperties,
unpack_border_color,
pack_border_color,
border_color_shorthand_value_parse);
- _gtk_css_shorthand_property_register (g_param_spec_boxed ("border-image",
- "Border Image",
- "Border Image",
- GTK_TYPE_BORDER_IMAGE, 0),
+ _gtk_css_shorthand_property_register ("border-image",
+ GTK_TYPE_BORDER_IMAGE,
border_image_subproperties,
_gtk_border_image_unpack,
_gtk_border_image_pack,
if (value == NULL)
continue;
- _gtk_css_lookup_set (lookup, id, value);
+ _gtk_css_lookup_set (lookup, id, NULL, value);
}
}